package com.four.reimbursemanage.dao;

import com.four.reimbursemanage.entity.CondolenceApply;
import com.four.reimbursemanage.entity.OutmoneyApply;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * 出差报销申请Mapper接口
 * 
 * @author lwy
 * @date 2024-09-22
 */
@Mapper
public interface OutmoneyApplyMapper 
{
    /**
     * 查询出差报销申请
     * 
     * @param id 出差报销申请主键
     * @return 出差报销申请
     */
    @Select("select * from outmoney_apply where id=#{id}")
    public OutmoneyApply selectOutmoneyApplyById(Integer id);

    /**
     * 查询出差报销申请列表
     *
     * @return 出差报销申请集合
     */@Select("<script>" +
            "SELECT id,member_name as memberName,out_apply as outApply,out_start as outStart,out_end as outEnd,address,startdate,enddate,fare,room_money as roomMoney,travel_day as travelDay,travel_money as travelMoney,room_address as roomAddress,room_day as roomDay,roomq_money as roomqMoney,sum_small as sumSmall,sum_money as sumMoney,sum_big as sumBig,people_num as peopleNum,is_car as isCar,traffic_aid as trafficAid,food_aid as foodAid,sum,prove_people as provePeople,rill,state FROM outmoney_apply" +
            "<where>" +
            "    <if test=\"memberName != null\">" +
            "       <bind name=\"Key\" value=\"'%'+memberName+'%'\"/>" +
            "       member_name like #{Key}"+
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<OutmoneyApply> selectOutmoneyApplyList(int start, int size,
                                                       String memberName,Integer state);

     /*查询本人申请*/
    @Select("<script>" +
            "SELECT id,number,member_name as memberName,out_apply as outApply,out_start as outStart,out_end as outEnd,address,startdate,enddate,fare,room_money as roomMoney,travel_day as travelDay,travel_money as travelMoney,room_address as roomAddress,room_day as roomDay,roomq_money as roomqMoney,sum_small as sumSmall,sum_money as sumMoney,sum_big as sumBig,people_num as peopleNum,is_car as isCar,traffic_aid as trafficAid,food_aid as foodAid,sum,prove_people as provePeople,rill,state FROM outmoney_apply" +
            "<where>" +
            "    <if test=\"memberName != null\">" +
            "       <bind name=\"Key\" value=\"'%'+memberName+'%'\"/>" +
            "       member_name like #{Key}"+
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<OutmoneyApply> selectByUser(int start, int size,
                                            String memberName,Integer state,String number);

    /*分页*/
    @Select("<script>" +
            "SELECT count(*) FROM outmoney_apply" +
            "<where>" +
            "    <if test=\"memberName != null\">" +
            " <bind name=\"Key\" value=\"'%'+memberName+'%'\"/>" +
            "        member_name like #{Key} " +
            "    </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countOutmoneyApply(String memberName, Integer state);

    /*查询本人申请分页*/
    @Select("<script>" +
            "SELECT count(*) FROM outmoney_apply" +
            "<where>" +
            "    <if test=\"memberName != null\">" +
            " <bind name=\"Key\" value=\"'%'+memberName+'%'\"/>" +
            "        member_name like #{Key} " +
            "    </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countOutmoneyApplyUser(String memberName, Integer state, String number);

    /**
     * 新增出差报销申请
     * 
     * @param outmoneyApply 出差报销申请
     * @return 结果te,
     */
    @Insert("insert into outmoney_apply(number,member_name,out_apply,out_start,out_end,address,startdate,enddate,fare,room_money,travel_day,travel_money,room_address,room_day,roomq_money,sum_small,sum_money,sum_big,people_num,is_car,traffic_aid,food_aid,sum,prove_people,rill,state)" +
            "values (#{number},#{memberName},#{outApply},#{outStart},#{outEnd},#{address},#{startdate},#{enddate},#{fare},#{roomMoney},#{travelDay},#{travelMoney},#{roomAddress},#{roomDay},#{roomqMoney},#{sumSmall},#{sumMoney},#{sumBig},#{peopleNum},#{isCar},#{trafficAid},#{foodAid},#{sum},#{provePeople},#{rill},4)")
    public int insertOutmoneyApply(OutmoneyApply outmoneyApply);

    /**
     * 修改出差报销申请
     * 
     * @param outmoneyApply 出差报销申请
     * @return 结果
     */
    @Update("<script>" +
            "  update outmoney_apply" +
            "        <set>" +
            "            <if test=\"null != memberName\"> " +
            "                member_name = #{memberName}," +
            "            </if>" +
            "            <if test=\"null != outApply\"> " +
            "                out_apply = #{outApply}," +
            "            </if>" +
            "            <if test=\"null != outStart\"> " +
            "                out_start = #{outStart}," +
            "            </if>" +
            "            <if test=\"null != outEnd\"> " +
            "                out_end = #{outEnd}," +
            "            </if>" +
            "            <if test=\"null != address\"> " +
            "                address = #{address}," +
            "            </if>" +
            "            <if test=\"null != startdate\"> " +
            "                startdate = #{startdate}," +
            "            </if>" +
            "            <if test=\"null != enddate\"> " +
            "                enddate = #{enddate}," +
            "            </if>" +
            "            <if test=\"null != fare\"> " +
            "                fare = #{fare}," +
            "            </if>" +
            "            <if test=\"null != roomMoney\"> " +
            "                room_money = #{roomMoney}," +
            "            </if>" +
            "            <if test=\"null != travelDay\"> " +
            "                travel_day = #{travelDay}," +
            "            </if>" +
            "            <if test=\"null != travelMoney\"> " +
            "                travel_money = #{travelMoney}," +
            "            </if>" +
            "            <if test=\"null != roomAddress\"> " +
            "                room_address = #{roomAddress}," +
            "            </if>" +
            "            <if test=\"null != roomDay\"> " +
            "                room_day = #{roomDay}," +
            "            </if>" +
            "            <if test=\"null != roomqMoney\"> " +
            "                roomq_money = #{roomqMoney}," +
            "            </if>" +
            "            <if test=\"null != sumSmall\"> " +
            "                sum_small = #{sumSmall}," +
            "            </if>" +
            "            <if test=\"null != sumMoney\"> " +
            "                sum_money = #{sumMoney}," +
            "            </if>" +
            "            <if test=\"null != sumBig\"> " +
            "                sum_big = #{sumBig}," +
            "            </if>" +
            "            <if test=\"null != peopleNum\"> " +
            "                people_num = #{peopleNum}," +
            "            </if>" +
            "            <if test=\"null != isCar\"> " +
            "                is_car = #{isCar}," +
            "            </if>" +
            "            <if test=\"null != trafficAid\"> " +
            "                traffic_aid = #{trafficAid}," +
            "            </if>" +
            "            <if test=\"null != foodAid\"> " +
            "                food_aid = #{foodAid}," +
            "            </if>" +
            "            <if test=\"null != sum\"> " +
            "                sum = #{sum}," +
            "            </if>" +
            "            <if test=\"null != provePeople\"> " +
            "                prove_people = #{provePeople}," +
            "            </if>" +
            "            <if test=\"null != rill\"> " +
            "                rill = #{rill}," +
            "            </if>" +
            "            <if test=\"null != state\"> " +
            "                state = #{state}," +
            "            </if>" +
            "        </set>" +
            "        where id = #{id}" +
            "</script>")
    public int updateOutmoneyApply(OutmoneyApply outmoneyApply);

    /*修改审批状态*/
    @Update("<script>" +
            "update  outmoney_apply " +
            "        <set>" +
            "            <if test=\"null!= state\">" +
            "                state =#{state}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public int updateStateById(OutmoneyApply outmoneyApply);

    /**
     * 删除出差报销申请
     * 
     * @param id 出差报销申请主键
     * @return 结果
     */
    public int deleteOutmoneyApplyById(Integer id);

    /**
     * 批量删除出差报销申请
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteOutmoneyApplyByIds(Integer[] ids);
}
